/********************************************************************
Name: Sensitivity to Control Group Size, Fixed Effects (Figure A2)
Author: Dan Thompson
Date: September 2021
Description: 

********************************************************************/

clear all
set matsize 11000
set maxvar 15000
gl path = "~/Dropbox/Mariel Effects"

* Bring in the county level analysis data
use "$path/Replication/data/county_analysis_data.dta", clear
keep if year<=1980

* Set up the output matrix
matrix define Output = J(304, 2, .)

* Loop over the size of the control pool and estimate the effect size
local row = 0
qui forval i=25(10)3055 {
	local ++row
	reghdfe rep_vs miami_1980_plus if rank<=`i', a(rank year) vce(cluster rank)
	matrix Output[`row', 1] = `i'
	matrix Output[`row', 2] = _b[miami_1980_plus]
	noi di "top `i' closest counties  $S_TIME"
}

* Save the effect sizes across number of counties in the control pool
clear
svmat Output
rename (Output1 Output2) (num_counties effect) 
save "$path/Replication/modified_data/fixed_effects_sensitivity.dta", replace

* Plot the difference in the effects across number of counties in the control pool
// Figure A2
use "$path/Replication/modified_data/fixed_effects_sensitivity.dta", clear
replace effect = effect*100
twoway (line effect num_counties, lc(gs2)), ///
	 xti("Number of Counties Included") ///
	 yti("Estimated Treatment Effect (% Points)") ///
	 ylab(0(2)10) ysc(r(0 10)) ///
	 xli(250, lc(gs6) lp(dot)) ///
	 xli(500, lc(gs6) lp(dot)) ///
	 xli(1500, lc(gs6) lp(dot)) ///
	 graphregion(color(white)) ///
	 name("fe_sensitivity", replace)
graph export "$path/Replication/output/fe_sensitivity.pdf", ///
	replace name("fe_sensitivity")
